package web.handler


import org.json.JSONObject
import web.request.jsonOf

class OnPayCancelHandler(json: JSONObject) : AbstractHandler(json, REQ) {

    companion object {

        const val REQ = "pay.cancel"
    }

    override fun exec(): JSONObject {

        if (!OnPayHandler.payFlag) {
            throw IllegalStateException("No payment request was initiated")
        }

        val appId = json.getString(OnPayHandler.FIELD_APPID)

        if (appId != OnPayHandler.payAppId) {
            throw IllegalStateException("appId:${appId} fail")
        }

        OnPayHandler.payCancel()

        return jsonOf(MSG_OK, CODE_OK)
    }
}